﻿using Ewelve_Mouth_HD.BLL;
using Ewelve_Mouth_HD.DAL;
using Ewelve_Mouth_HD.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Ewelve_Mouth_HD.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly UserBll userBll;
        private readonly ILogger<UserController> _logger;

        public UserController(UserBll _userBll, ILogger<UserController> logger)
        {
            userBll = _userBll;
            _logger = logger;
        }
        /// <summary>
        /// 用户添加
        /// </summary>
        /// <param name="W"></param>
        /// <returns></returns>
        [HttpPost]
        public int UserAdd(UserInfo W)
        {
            try
            {
                return userBll.UserAdd(W);
            }
            catch (Exception)
            {
                _logger.LogInformation("用户添加错误");
                throw;
            }
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        [HttpGet]
        public int UserLog(string UserName, string Password)
        {
            try
            {
                _logger.LogInformation("用户"+UserName+"登录");
                return userBll.UserLog(UserName, Password);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
